//////////////////////////////////////
// external variables
/////////////////////////////////////

float width = 200, height = 200;
float innerRadius = 60;
float outerRadius = 100;
float4 innerLoss = 0.4f;

struct VertexOut
{
	float4 pos : POSITION0;
	float2 Coords : TEXCOORD0;
};

VertexOut BrushVertexShader(float4 posIn : POSITION0, float2 texCoord : TEXCOORD0)
{
	VertexOut ret = (VertexOut)0;
	ret.pos = posIn;
	ret.Coords = texCoord;
	return ret;
}

float4 BrushPixelShader(float4 posIn : POSITION, float2 texCoord : TEXCOORD0) : COLOR0
{
	float2 curPos = float2(texCoord.x * width, texCoord.y * height);
	float2 midPoint = float2(width / 2, height / 2);

	float2 diff = (curPos - midPoint);
	float dist = sqrt(dot(diff, diff));

	float4 retColor = float4(1, 1, 1, 1);
	if(dist > outerRadius)
		retColor = float4(0, 0, 0, 0);
	else
	{
		retColor = float4(1, 1, 1, 1);
		if(dist <= innerRadius)
		{
			float loss = (dist / innerRadius) * innerLoss;
			retColor.a *= 1.0f - loss;
		}
		else if(dist > innerRadius)
		{
			dist -= innerRadius;
			float loss = innerLoss + (dist / (outerRadius - innerRadius)) * (1 - innerLoss);
			retColor.a *= 1.0f - loss;
		}
	}
	return retColor;
}

technique BrushTechnique
{
    pass ColorPass
    {
		VertexShader = compile vs_3_0 BrushVertexShader();
        PixelShader = compile ps_3_0 BrushPixelShader();
    }
}
